//
//  CustomCollectionViewCell.m
//  豆瓣电影
//
//  Created by dllo on 16/6/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CustomCollectionViewCell.h"
#import "MovieModel.h"
#import "UIImageView+WebCache.h"

#define kWith self.contentView.frame.size.width
#define kHeight self.contentView.frame.size.height


@interface CustomCollectionViewCell()

@property (nonatomic, retain) UIImageView *movieImageView;

@property (nonatomic, retain) UILabel *nameLabel;

@property (nonatomic, retain) UIImageView *backImageView;


@end

@implementation CustomCollectionViewCell

-(void)dealloc
{
    [_backImageView release];
    [_movieImageView release];
    [_nameLabel release];
    [_cellModel release];
    [super dealloc];
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bg_eventlistcell.png"]];
        [self.contentView addSubview:self.backImageView];
        
        self.movieImageView = [[UIImageView alloc]init];
        [self.backImageView addSubview:self.movieImageView];
        
        
        self.nameLabel = [[UILabel alloc]init];
        self.nameLabel.textAlignment = NSTextAlignmentCenter;
        self.nameLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
        self.nameLabel.font = [UIFont systemFontOfSize:15];
        
        [self.backImageView addSubview:self.nameLabel];
        
        [self.nameLabel release];
        [self.movieImageView release];
        [self.backImageView release];

    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.backImageView.frame = self.contentView.bounds;
    
    self.movieImageView.frame = CGRectMake(0, 0, self.backImageView.frame.size.width, self.backImageView.frame.size.height * 0.8);
    
    self.nameLabel.frame = CGRectMake(0, self.backImageView.frame.size.height * 0.8 , self.backImageView.frame.size.width, self.backImageView.frame.size.height * 0.2);  
}


-(void)setCellModel:(MovieModel *)cellModel
{
    if (_cellModel != cellModel) {
        [_cellModel release];
        _cellModel = [cellModel retain];
    }
    
    NSURL * url = [NSURL URLWithString:cellModel.pic_url];
    
    [self.movieImageView sd_setImageWithURL:url];
    
    self.nameLabel.text = cellModel.movieName;
    
}


@end

















